package com.xinfu.newproject.presenter;

import com.xinfu.newproject.bean.complaint.bean.ComplaintDetailBean;
import com.xinfu.newproject.bean.complaint.bean.ComplaintEvaluateBean;
import com.xinfu.newproject.bean.complaint.bean.ComplaintRecordBean;
import com.xinfu.newproject.bean.complaint.bean.SubmitComplaintBean;
import com.xinfu.newproject.bean.complaint.body.ComplaintDetailBody;
import com.xinfu.newproject.bean.complaint.body.ComplaintEvaluateBody;
import com.xinfu.newproject.bean.complaint.body.ComplaintRecordBody;
import com.xinfu.newproject.bean.complaint.body.SubComplaintBody;
import com.xinfu.newproject.callback.MyCallBack;
import com.xinfu.newproject.model.complaint.ComplaintModel;
import com.xinfu.newproject.view.IView;

import io.reactivex.disposables.Disposable;

public class ComplaintPresenter {
    private IView.IComplaintView mIComplaintView;

    private ComplaintModel mComplaintModel;

    public ComplaintPresenter(IView.IComplaintView iComplaintView) {
        this.mIComplaintView = iComplaintView;
        mComplaintModel = new ComplaintModel();
    }

    /**
     * 提交投诉
     */
    public void submitComplaint() {
        mIComplaintView.showProgress();
        SubComplaintBody subComplaintBody = new SubComplaintBody(mIComplaintView.header(), mIComplaintView.userId(), mIComplaintView.type(), mIComplaintView.name()
                , mIComplaintView.telephone(), mIComplaintView.picture(), mIComplaintView.content(), mIComplaintView.projectId(), mIComplaintView.tenantId());

        mComplaintModel.submitComplaint(subComplaintBody, new MyCallBack<SubmitComplaintBean>() {
            @Override
            public void onSuccess(SubmitComplaintBean submitComplaintBean) {
                mIComplaintView.hideProgress();
                if (submitComplaintBean.isSuccess()) {
                    mIComplaintView.getMsg(submitComplaintBean);
                } else {
                    mIComplaintView.showToast(submitComplaintBean.getMessage());
                }
//                mISubmitRepairView.showToast(addRepairBean.getMessage());

            }

            @Override
            public void onError(String header, String message) {
                mIComplaintView.hideProgress();
                mIComplaintView.showToast(message);
            }

            @Override
            public void onDispose(Disposable disposable) {
                mIComplaintView.closeDispose(disposable);
            }
        });
    }

    /**
     * 投诉记录
     */
    public void complaintRecord() {
        mIComplaintView.showProgress();
        ComplaintRecordBody complaintRecordBody = new ComplaintRecordBody(mIComplaintView.header(), mIComplaintView.userId());

        mComplaintModel.complaintRecord(complaintRecordBody, new MyCallBack<ComplaintRecordBean>() {
            @Override
            public void onSuccess(ComplaintRecordBean complaintRecordBean) {
                mIComplaintView.hideProgress();
                if (complaintRecordBean.isSuccess()) {
                    mIComplaintView.getMsg(complaintRecordBean);
                } else {
                    mIComplaintView.showToast(complaintRecordBean.getMessage());
                }
//                mISubmitRepairView.showToast(addRepairBean.getMessage());

            }

            @Override
            public void onError(String header, String message) {
                mIComplaintView.hideProgress();
                mIComplaintView.showToast(message);
            }

            @Override
            public void onDispose(Disposable disposable) {
                mIComplaintView.closeDispose(disposable);
            }
        });
    }

    /**
     * 投诉详情
     */
    public void complaintDetail() {
        mIComplaintView.showProgress();
        ComplaintDetailBody complaintDetailBody = new ComplaintDetailBody(mIComplaintView.header(), mIComplaintView.complaintId());

        mComplaintModel.complaintDetail(complaintDetailBody, new MyCallBack<ComplaintDetailBean>() {
            @Override
            public void onSuccess(ComplaintDetailBean complaintDetailBean) {
                mIComplaintView.hideProgress();
                if (complaintDetailBean.isSuccess()) {
                    mIComplaintView.getMsg(complaintDetailBean);
                } else {
                    mIComplaintView.showToast(complaintDetailBean.getMessage());
                }
//                mISubmitRepairView.showToast(addRepairBean.getMessage());

            }

            @Override
            public void onError(String header, String message) {
                mIComplaintView.hideProgress();
                mIComplaintView.showToast(message);
            }

            @Override
            public void onDispose(Disposable disposable) {
                mIComplaintView.closeDispose(disposable);
            }
        });
    }

    /**
     * 投诉评价
     */
    public void complaintEvaluate() {
        mIComplaintView.showProgress();
        ComplaintEvaluateBody complaintEvaluateBody = new ComplaintEvaluateBody(mIComplaintView.header(), mIComplaintView.content(), mIComplaintView.picture(), mIComplaintView.name(), mIComplaintView.tenantId(), mIComplaintView.status(), mIComplaintView.complaintId());

        mComplaintModel.complaintEvaluate(complaintEvaluateBody, new MyCallBack<ComplaintEvaluateBean>() {
            @Override
            public void onSuccess(ComplaintEvaluateBean complaintEvaluateBean) {
                mIComplaintView.hideProgress();
                if (complaintEvaluateBean.isSuccess()) {
                    mIComplaintView.getMsg(complaintEvaluateBean);
                } else {
                    mIComplaintView.showToast(complaintEvaluateBean.getMessage());
                }
//                mISubmitRepairView.showToast(addRepairBean.getMessage());

            }

            @Override
            public void onError(String header, String message) {
                mIComplaintView.hideProgress();
                mIComplaintView.showToast(message);
            }

            @Override
            public void onDispose(Disposable disposable) {
                mIComplaintView.closeDispose(disposable);
            }
        });
    }
}
